package com.cn.book;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@SpringBootApplication
@RestController
public class ConsulConsumerDiscoveryClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsulConsumerDiscoveryClientApplication.class, args);
    }

    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping(path = "/getService")
    public List<ServiceInstance> getService(@RequestParam("serviceId") String serviceId) {
        return discoveryClient.getInstances(serviceId);
    }
}
